﻿/*
题目: 四数相加 II

给你四个整数数组 nums1、nums2、nums3 和 nums4 ，数组长度都是 n ，请你计算有多少个元组 (i, j, k, l) 能满足：

0 <= i, j, k, l < n
nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0

https://leetcode.cn/problems/4sum-ii/description/
*/

#include <iostream>
#include <random>
#include <string>
#include <vector>
#include <list>
#include "TreeNode.hpp"
#include "ListNode.hpp"
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>

using namespace std;

class Solution {
public:
    int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {
        unordered_map<long long, int> mp;
        for (int num1 : nums1) {
            for (int num2 : nums2) {
                mp[(long long)num1 + num2] ++;
            }
        }

        int cnt = 0;
        for (int num3 : nums3) {
            for (int num4 : nums4) {
                if (mp.count(-((long long)num3 + num4)) == true)
                    cnt += mp[-((long long)num3 + num4)];
            }
        }
        return cnt;
    }
};